// function editCart(cartItemId, buyCount) {
//     window.location.href = "cart.do?operate=editCart&cartItemId=" + cartItemId + "&buyCount=" + buyCount;
// }
//
// function editCartMinus(cartItemId, buyCount) {
//     if (buyCount <= 1) {
//         alert("最小数量为1");
//         return;
//     }
//     editCart(cartItemId, buyCount - 1);
// }
//
// function editCartAdd(cartItemId, buyCount, bookCount) {
//     if (buyCount >= bookCount) {
//         alert("超出库存最大数量");
//         return;
//     }
//     editCart(cartItemId, buyCount + 1);
// }

window.onload = function () {
    var vue = new Vue({
        el: "#cart_div",
        data: {
            cart: {}
        },
        mounted: function () {
            this.getCart();
        },
        methods: {
            getCart: function () {
                axios({
                    "method": "post",
                    "url": "cart.do",
                    "params": {
                        "operate": "cartInfo"
                    }
                }).then(function (value) {
                    var cart = value.data;
                    vue.cart = cart;

                }).catch(function (error) {
                    console.log(error);
                });
            },
            editCart: function (cartItemId, buyCount) {
                axios({
                    "method": "post",
                    "url": "cart.do",
                    "params": {
                        "operate": "editCart",
                        "cartItemId": cartItemId,
                        "buyCount": buyCount
                    }
                }).then(function (value) {
                    //var cart = value.data;
                    //vue.cart = cart;
                    vue.getCart();

                }).catch(function (error) {
                    console.log(error);
                });

            }, editCartMinus: function (cartItemId, buyCount) {
                if (buyCount <= 1) {
                    alert("最小数量为1");
                    return;
                }
                this.editCart(cartItemId, buyCount - 1);

            }, editCartAdd: function (cartItemId, buyCount, bookCount) {
                if (buyCount >= bookCount) {
                    alert("超出库存最大数量");
                    return;
                }
                this.editCart(cartItemId, buyCount + 1);
            }
        }
    });
}